package
{
	import com.nana.framework.base.App;
	import com.nana.framework.debug.Debug;
	import com.nana.framework.debug.FPS;
	import com.nana.framework.ui.manager.FullScreenPanelManager;
	import com.nana.framework.ui.manager.PopUpManager;
	import com.nana.framework.ui.manager.UIManager;
	import com.nana.petadventure.app.AppControllerList;
	import com.nana.petadventure.app.AppView;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class main extends Sprite
	{

		private var _loader:Loader;
		
		public function main()
		{
			if(this.stage){
				this.init();
			}else{
				this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
			}
		}
		
		private function addedToStage(event:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
			this.init();
		}
		
		private function init():void
		{
			// TODO: ------ 在entry中设置 
			App.appStage = this.stage;
			
			AppView.getInstance().init(App.appStage, this);
//			DataProxy.getInstance().httpurl = AppData.getInstance().postUrl;
//			StatisticsProxy.getInstance().httpUrl = (AppData.getInstance().statisticsUrl + AppData.getInstance().sessionkey);
//			StatisticsProxy.getInstance().setProperty(AppData.getInstance().myID, false, false);
//			StatisticsProxy.getInstance().sendActionStatistics(StatisticsProxy.statLoading);
			UIManager.registerPopUpManager(PopUpManager);
//			UIManager.registerLanguageManager(LanguageDebugManager);
			UIManager.registerFullScreenPanelManager(FullScreenPanelManager);
//			UIManager.getDragManager().parent = AppView.getInstance().mouseLayer;
//			UIManager.getMouseManager().parent = AppView.getInstance().mouseLayer;
			UIManager.getPopUpManager().parent = AppView.getInstance().popUpLayer;
			UIManager.getToolTipManager().parent = AppView.getInstance().tipLayer;
//			UIManager.getToolTipManager().popTipsParent = AppView.getInstance().popUpLayer;
			UIManager.getFullScreenPanelManager().parent = AppView.getInstance().panelLayer;
//			var fontClass:Class = Dll.getInstance().getClassByName(AppFont.FONTLIBRARY);
//			AppFont.fontClass = fontClass;
//			AppFont.registerFont();
//			TextFieldFactory.getInstance().registerStyle(Dll.getInstance().getClassByName("STYLE"), Dll.getInstance().getXMLDataByName("styleConfig"), AppFont.affirmatoryFont, AppFont.affirmatoryFontEmbed);
			if (Debug.isDebug){
				var fps:FPS = new FPS();
				AppView.getInstance().uiLayer.addChild(fps);
				fps.x = (App.appStage.width - fps.width) / 2 + 200;
			}
			this.gameStart();
		}
		
		private function gameStart():void
		{
			AppControllerList.getInstance().appController.start();
		}
	}
}